//
//  CircleView.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/31.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "CircleView.h"

@interface CircleView()

@property (nonatomic,strong)UIBezierPath *path;
@property (nonatomic,strong)CAShapeLayer *shapeLayer;
@property (nonatomic,strong)CAShapeLayer *bgLayer;


@end

@implementation CircleView
//环形进度条
//http://blog.csdn.net/dolacmeng/article/details/46291111
//http://blog.csdn.net/xiangzhang321/article/details/42688133
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _path = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
        _bgLayer = [CAShapeLayer layer];
        _bgLayer.frame = self.bounds;
        _bgLayer.fillColor = [UIColor clearColor].CGColor;
        _bgLayer.lineWidth = 2.0;
        _bgLayer.strokeColor = [UIColor redColor].CGColor;
        _bgLayer.strokeStart = 0;
        _bgLayer.strokeEnd = 1;
        _bgLayer.path = _path.CGPath;
        [self.layer addSublayer:_bgLayer];
        
        _shapeLayer = [CAShapeLayer layer];
        _shapeLayer.frame = self.bounds;
        _shapeLayer.fillColor = [UIColor clearColor].CGColor;
        _shapeLayer.lineWidth = 2;
        //_shapeLayer.lineCap = kCALineCapRound;
        _shapeLayer.strokeColor = [UIColor redColor].CGColor;
        _shapeLayer.strokeStart = 0;
        _shapeLayer.strokeEnd = 0;
        
        _shapeLayer.path = _path.CGPath;
        [self.layer addSublayer:_shapeLayer];
        
        
    }
    
    return self;
}

@synthesize value = _value;

-(void)setValue:(CGFloat)value{
    _value = value;
    _shapeLayer.strokeEnd = value;
}

-(CGFloat)value{
    return _value;
}

@synthesize lineColor = _lineColor;
-(void)setLineColor:(UIColor *)lineColor{
    _lineColor = lineColor;
    _shapeLayer.strokeColor = lineColor.CGColor;
}

-(UIColor *)lineColor{
    return _lineColor;
}

@synthesize lineWidth = _lineWidth;
-(void)setLineWidth:(CGFloat)lineWidth{
    _lineWidth = lineWidth;
    _shapeLayer.lineWidth = lineWidth;
    _bgLayer.lineWidth = lineWidth;
}

-(CGFloat)lineWidth{
    return _lineWidth;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
